package cn.edu.fzu.delivery.remoting;

import cn.edu.fzu.delivery.http.HttpClient;
import cn.edu.fzu.delivery.http.HttpClientFactory;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 查询位置信息
 * 
 * @author fangxin
 * @date 2022年11月23日
 */
public abstract class LocationApi<T> {

    private static final Logger log = LoggerFactory.getLogger(LocationApi.class);

    private final HttpClient    hc  = HttpClientFactory.get(2000, 6000);

    public T get() {
        String rsp;
        try {
            rsp = hc.get(getUrl());
        } catch (Exception e) {
            log.error("call api error. errmsg={}", e.getMessage(), e);
            return null;
        }

        if (StringUtils.isBlank(rsp)) {
            return null;
        }
        return transfer(JSON.parseObject(rsp));
    }


    public abstract String getUrl();


    public abstract T transfer(JSONObject data);

}
